package cn.minhx.domain.strategy.service.rule.tree.factory;

import cn.minhx.domain.strategy.model.valobj.RuleLogicCheckTypeVO;
import cn.minhx.domain.strategy.model.valobj.tree.RuleTreeVO;
import cn.minhx.domain.strategy.service.rule.tree.ILogicTreeNode;
import cn.minhx.domain.strategy.service.rule.tree.engine.IDecisionTreeEngine;
import cn.minhx.domain.strategy.service.rule.tree.engine.impl.DecisionTreeEngine;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.stereotype.Service;

import java.util.Map;

/**
 * 规则树工厂
 * 由决策树工厂管理规则节点的注入和决策树引擎的创建。
 * 在使用的时候，可以通过 openLogicTree 方法获取执行器。执行器提供了规则的执行操作。
 *
 * @author min
 */
@Service
public class DefaultTreeFactory {

    private final Map<String, ILogicTreeNode> logicTreeNodeMap;

    public DefaultTreeFactory(Map<String, ILogicTreeNode> logicTreeNodeMap) {
        this.logicTreeNodeMap = logicTreeNodeMap;
    }

    public IDecisionTreeEngine openLogicTree(RuleTreeVO ruleTreeVO) {
        return new DecisionTreeEngine(logicTreeNodeMap, ruleTreeVO);
    }

    /**
     * 决策树个动作实习
     */
    @Data
    @Builder
    @AllArgsConstructor
    @NoArgsConstructor
    public static class TreeActionEntity {
        private RuleLogicCheckTypeVO ruleLogicCheckType;
        private StrategyAwardVO strategyAwardVO;
    }

    @Data
    @Builder
    @NoArgsConstructor
    @AllArgsConstructor
    public static class StrategyAwardVO {
        /**
         * 抽奖奖品ID - 内部流转使用
         */
        private Long awardId;
        /**
         * 抽奖奖品规则
         */
        private String awardRuleValue;
    }

}
